package com.hexinfo.dmpro.monitor.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.common.annotation.Log;
import com.hexinfo.dmpro.common.base.Page;
import com.hexinfo.dmpro.monitor.config.MonitorCache;
import com.hexinfo.dmpro.monitor.model.MonitorClusResModel;
import com.hexinfo.dmpro.monitor.model.base.MonitorReq;
import com.hexinfo.dmpro.monitor.service.MonitorService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author peng
 * @date 2021/10/14 9:36
 */
@RestController
@RequestMapping("/monitor_api/monitor")
public class MonitorController {

    @Autowired
    private MonitorService monitorService;

    @Autowired
    private MonitorCache monitorCache;

    /**
     * 获取大数据子集群信息
     * @param req
     * @return
     */
    @PostMapping(value = "/selAllCluster")
    public ResponseEntity<Object> selAllCluster(@RequestBody MonitorClusResModel req) {
        return new ResponseEntity<>(monitorService.selAllCluster(req), HttpStatus.OK);
    }

    /**
     * 获取大数据集群信息
     * @param req
     * @return
     */
    @PostMapping(value = "/selAllCm")
    public ResponseEntity<Object> selAllCm(@RequestBody MonitorReq req) {
        return new ResponseEntity<>(monitorCache.getCms(req.getCenterId()), HttpStatus.OK);
    }

    @Log("查询任务监控信息")
    @GetMapping(value = "/selTaskInfo")
    public ResponseEntity<Object> selTaskInfo(Page page, @Param("int")int current, MonitorReq req) {
        page.setPageIndex(current-1);
        return new ResponseEntity<>(monitorService.selTaskInfo(page, req), HttpStatus.OK);
    }

    @Log("查询任务监控信息")
    @PostMapping(value = "/selTaskCount")
    @AnonymousAccess
    public ResponseEntity<Object> selTaskCount(@RequestBody MonitorReq req) {
        return new ResponseEntity<>(monitorService.selTaskCount(req), HttpStatus.OK);
    }

    @Log("任务执行数量统计图表")
    @PostMapping(value = "/selTaskJobCount")
    @AnonymousAccess
    public ResponseEntity<Object> selTaskJobCount(@RequestBody MonitorReq req) {
        return new ResponseEntity<>(monitorService.selTaskJobCount(req), HttpStatus.OK);
    }

    @Log("任务统计图表")
    @PostMapping(value = "/selTaskJobTime")
    @AnonymousAccess
    public ResponseEntity<Object> selTaskJobTime(@RequestBody MonitorReq req) {
        return new ResponseEntity<>(monitorService.selTaskJobTime(req), HttpStatus.OK);
    }

    @Log("大屏任务状态数量汇总")
    @GetMapping(value = "/selTaskStateCount")
    @AnonymousAccess
    public ResponseEntity<Object> selTaskStateCount(String areaId,String sortId,String monitorType) {
        return new ResponseEntity<>(monitorService.selTaskStateCount(areaId,sortId,monitorType), HttpStatus.OK);
    }

    @Log("大屏任务时间数量汇总图表")
    @GetMapping(value = "/selTaskJobCountTime")
    @AnonymousAccess
    public ResponseEntity<Object> selTaskJobCountTime(String areaId,String sortId) {
        return new ResponseEntity<>(monitorService.selTaskJobCountTime(areaId,sortId), HttpStatus.OK);
    }

    @Log("大屏服务状态")
    @GetMapping(value = "/selServiceState")
    @AnonymousAccess
    public ResponseEntity<Object> selServiceState(String areaId,String sortId) {
        return new ResponseEntity<>(monitorService.selServiceState(areaId,sortId), HttpStatus.OK);
    }

}
